import router from './router'
import { useUserStore } from '@/stores/user'
import { ElMessage } from 'element-plus'

// 白名单路由
const whiteList = ['/login', '/404', '/403']

router.beforeEach((to, from, next) => {
  const userStore = useUserStore()
  const token = userStore.token

  if (token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})

router.afterEach(() => {
  // 路由加载完成后的处理
}) 